package persistences;

import java.sql.Connection;
import java.sql.SQLException;

import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanHandler;

import dto.majorPlanDTO;
import util.DBUtil;

public class majorPlanDAO {
	private DBUtil dbUtil;
	private Connection conn;

	public majorPlanDAO() {
		dbUtil = new DBUtil();
		conn = dbUtil.getConnection();
	}

	public boolean findmajorPlan(
			String majorName, 
			String majorId,
			String trainingPurpose,
			String trainingContent, 
			String classHours,
			String teacher) {
		boolean result = false;
		QueryRunner qr = new QueryRunner();
		majorPlanDTO  majorPlanDTO = null;
		
		String sql ="select majorName,majorId,trainingPurpose,trainingContent,classHours,teacher from t_base_user_info where id=? and name=? and planYear=? and startDate=? and endDate=? and majorPlane=?";
		String params[] = new String[6];
		params[0] = majorName;
		params[1] = majorId;
		params[2] = trainingPurpose;
		params[3] = trainingContent;
		params[4] = classHours;
		params[5] = teacher;
		
		try{
			majorPlanDTO = qr.query(conn, sql, new BeanHandler<majorPlanDTO>(majorPlanDTO.class),params);	
		} catch (SQLException e) {
			e.printStackTrace();
		}
		
		if (majorPlanDTO != null){
			result = true;
			System.out.println(majorPlanDTO.getmajorName()+"  "+majorPlanDTO.getmajorId()+"  "+majorPlanDTO.gettrainingPurpose()+"  "+majorPlanDTO.gettrainingContent()+"  "+majorPlanDTO.getclassHours()+"  "+majorPlanDTO.getTeacher());
		}
		
		return result;
	}

}

